package
{
	
	import com.ux.base.BLoader;
	
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	/**
	 * @author winnieQuad
	 */	
	public class ImgClip extends Sprite
	{
		private const SIZE_WIDTH : Number = 325;
		private const SIZE_HEIGHT : Number = 213;
		
		private var _bLoader : BLoader;
		private var _linkUrl : String;
		private var _target : String;
		
		
		public function ImgClip()
		{
			super();
		}
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// setter / getter
		//
		//-----------------------------------------------------------------------------------
		
		public function get target():String
		{
			return _target;
		}

		public function set target(value:String):void
		{
			_target = value;
		}

		public function get linkUrl():String
		{
			return _linkUrl;
		}

		public function set linkUrl(value:String):void
		{
			_linkUrl = value;
		}

		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// public functions
		//
		//-----------------------------------------------------------------------------------
		
		public function loadImg( url : String ):void
		{
			_bLoader = new BLoader( url, this, onLoadHandler );
		}
		
		
		public function ON():void
		{
			this.addEventListener( MouseEvent.CLICK, onClick );
		}
		
		
		public function OFF():void
		{
			this.removeEventListener( MouseEvent.CLICK, onClick );
		}
		
		override public function get width():Number
		{
			return SIZE_WIDTH;
		}
		
		override public function get height():Number
		{
			return SIZE_HEIGHT;
		}
		
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// private function
		//
		//-----------------------------------------------------------------------------------
		
		private function onLoadHandler():void
		{
			_bLoader.loadData.x = -_bLoader.loadData.width /2;
			_bLoader.loadData.y = -_bLoader.loadData.height /2;
		}		
		
		
		
		
		
		//-----------------------------------------------------------------------------------
		//
		// event Handler
		//
		//-----------------------------------------------------------------------------------
		
		protected function onClick(e:MouseEvent):void
		{
			navigateToURL( new URLRequest( linkUrl ), target );
		}
	}
}